package com.yz.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yz.common.R;
import com.yz.dto.SetmealDto;
import com.yz.entity.Setmeal;
import com.yz.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    /**
     * 保存新添加的套餐数据
     * @param setmealDto
     * @return
     */
    @PostMapping
    public R<String> save(@RequestBody SetmealDto setmealDto){
        setmealService.saveAndSetmealDish(setmealDto);
        return R.success("添加成功");
    }
    /**
     * 获取套餐分页数据
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R<Page<SetmealDto>> page(int page,int pageSize){
        Page<SetmealDto> setmealDtoPage = setmealService.pageAndCategoryName(page,pageSize);
        return R.success(setmealDtoPage);
    }

    /**
     * 删除套餐 单个或者多个
     * @param ids
     * @return
     */
    @DeleteMapping
    public R<String> delete(Long...ids){
        setmealService.deleteAndSetmeanDish(ids);
        return R.success("删除成功");
    }

    /**
     * 获取指定套餐分类下的菜品列表
     * @param setmeal
     * @return
     */
    @GetMapping("/list")
    public R<List<Setmeal>> list(Setmeal setmeal){
        log.info("Setmeal:{}",setmeal);
        LambdaQueryWrapper<Setmeal> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Setmeal::getCategoryId,setmeal.getCategoryId());
        wrapper.eq(Setmeal::getStatus,setmeal.getStatus());
        List<Setmeal> list = setmealService.list(wrapper);
        return R.success(list);
    }
}
